<?php
defined('_JEXEC') or die;
$user = JFactory::getUser();
if ($user->get('guest') == 1) {
	header('Location: '.substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], 'index.php')).'index.php');
}

$db =& JFactory::getDBO();
$query = 'SELECT * from #__users WHERE id = "'.$user->id.'"';
$db->setQuery( $query );
$db->query();
$rowuser = $db->loadObject();	

								
$input_skills = JText::_( 'Vælg én eller flere kompetencer' );       
$input_firma_navn = JText::_( 'Udfyld venligst rubrikken: “Firmanavn”' );       
$input_name = JText::_( 'Udfyld venligst rubrikken: “Kontaktpersonens fornavn”' );       
$input_lastname = JText::_( 'Udfyld venligst rubrikken: “Kontaktpersonens efternavn”' );       
$input_adresse = JText::_( 'Udfyld venligst både “Adresse”' );       
$input_post = JText::_( 'Udfyld venligst både “Postnr”' );       
$input_by_ = JText::_( 'Udfyld venligst både “By”' ); 
$input_cvr = JText::_( 'Der er ikke indtastet et gyldigt CVR-nummer' ); 
$input_cvr_invalid = JText::_( 'Indtast venligst et 8-cifret CVR-nummer' ); 
$input_telefone = JText::_( 'Indtast din telefonnummer' );       
$input_telefone_invalid = JText::_( 'Indtast venligst et 8-cifret telefonnummer' ); 
$input_email = JText::_( 'Indtast venligst en gyldig e-mail-adresse' );                        	       
$input_confirm_email = JText::_( 'De to indtastede e-mail-adresser er ikke ens' );
$input_password = JText::_( 'Skriv venligst din ønskede adgangskode' );
$input_password_invalid = JText::_( 'Indtast venligst et 6-cifret adgangskode' ); 
$input_password2 = JText::_( 'De 2 indtastede adgangskoder er ikke ens' );
$input_accept = JText::_( 'Du skal markere, at du acceptere brugerbetingelserne, for at kunne gå videre' );
$input_oldpassword = JText::_( 'Indtast venligst din nuværende adgangskode' );
$input_oldpassword_invalid = JText::_( 'Indtast venligst et 6-cifret nuværende adgangskode' ); 
?>                        
 <script type="text/javascript"> 
 function dummytestdata() {
	
	$("#firma_navn").val('mwc'); 
	$("#name").val('dung'); 
	$("#lastname").val('le'); 
	$("#adresse").val('le van sy');  
	$("#post").val('1111'); 
	$("#by_").val('hcm'); 
	$("#cvr").val('12345678'); 
	$("#telefone").val('09089878'); 
	$("#email").val('le.dung@mwc.vn'); 
	$("#confirm_email").val('le.dung@mwc.vn'); 
	$("#password").val('123456'); 
	$("#password2").val('123456'); 
	$("#accept").attr("checked","checked"); 
 }                  
$(document).ready(function($) {
	   //dummytestdata();
		$("#post").mask("9999",{placeholder:""}); 
		$("#cvr").mask("99999999",{placeholder:""}); 
		$("#telefone").mask("99999999",{placeholder:""}); 
		 
		if( $('#system-message dd ul li').length > 0) {
			$('#msgbox').html($('#system-message dd ul li').html());
    		$('.btnhidden').click();
		}
	   $.validator.addMethod('defaultelefone', function (value) { 
			if(value=='') return true;	
			return /^\d{8}$/.test(value); 
	   }, '');
	   $.validator.addMethod('defaulcvr', function (value) { 
			if(value=='') return true;	
			return /^\d{8}$/.test(value); 
	   }, '');
	   $.validator.addMethod('postalcode', function (value) { 
			if(value=='') return true;	
			return /^\d{4}$/.test(value); 
	   }, '');
	   $.validator.addMethod('checkpassword', function (value) { 
			if ( value.length < 6 && value.length >=1) { return false;}
			return true;
			
	   }, '');
	   
	   
	   	//jQuery("#post").mask("9999",{placeholder:""});  
		$("#tilmeldMalerfirmaFormEdit").validate(
			{
				errorPlacement: function(error, element) {			
			},
			invalidHandler: function(form, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
                //$('#alert').html(validator['errorList'][0]['message']);
				$('#msgbox').html(validator['errorList'][0]['message']);
    			$('.btnhidden').click();
            	$('#f_focus').html(validator['errorList'][0]['element'].name);
				validator['errorList'][0]['element'].focus();
				$('#TB_overlay').attr("onclick","close_popup();");
				$('#TB_closeWindowButton').attr("onclick","close_popup();");
				
				var erro_len = validator['errorList'].length;
				//alert(errors);
				
				$("#tilmeldMalerfirmaFormEdit input").removeClass("border_red");
				$("#tilmeldMalerfirmaFormEdit textarea").removeClass("border_red");
				for($i=0;$i<errors;$i++) {
					$('#'+validator['errorList'][$i]['element'].name).addClass("border_red");
				}
				
				
			  } else {
			  }
			},
			rules: {
				
				firma_navn: "required",
				name: "required",
				lastname: "required",
				adresse: "required",
				post: {
					required: true
				},	
				by_: "required",
				cvr: {
					required: true,
					defaulcvr: true
				},
				telefone: {
					required: true,
					defaultelefone: true
				},
				email : {
					required: true,
					email:true,
				},		
				confirm_email : {
					required: true,
					equalTo: "#email"
				},				
				oldpassword : {
					required: true,
					checkpassword : true,
				}	,				
				password : {
					/*required: true,*/
					checkpassword : true,
				}	
				,				
				password2 : {
					/*required: true,*/
					checkpassword : true,
					equalTo: "#password"
				},
				accept : "required"	
			},
			messages: {
				firma_navn: "<?php echo $input_firma_navn; ?>",
				name: "<?php echo $input_name; ?>",
				lastname: "<?php echo $input_lastname; ?>",
				adresse: "<?php echo $input_adresse; ?>",
				post: "<?php echo $input_post; ?>",
				by_: "<?php echo $input_by_; ?>",
				cvr: {
					required : "<?php echo $input_cvr; ?>", 
					defaulcvr : "<?php echo $input_cvr_invalid; ?>", 
				},telefone: {
					required : "<?php echo $input_telefone; ?>", 
					defaultelefone : "<?php echo $input_telefone_invalid; ?>", 
				},
				email: "<?php echo $input_email; ?>",
				confirm_email: "<?php echo $input_confirm_email; ?>",
				oldpassword:  {
					required : "<?php echo $input_oldpassword; ?>", 
					checkpassword : "<?php echo $input_oldpassword_invalid; ?>", 
				},			
                password:  {
					required : "<?php echo $input_password; ?>", 
					checkpassword : "<?php echo $input_password_invalid; ?>", 
				},
				password2: "<?php echo $input_password2; ?>"
				
			}
		});
        close_popup=function(){		
    		var fel=$('#f_focus').html();
            $('#backoverlay').hide();
    		$('#show_popup').hide();
    		$('#' + fel ).focus();			
      };
	});
</script>               
<div class="inner clearfix">
                        <!-- Tilmeld Malerfirma Form-->
                        <?php $info = getArticles(12);
							  $images = json_decode($info[0]->images);
							  $session =& JFactory::getSession();  
						?>
                       
                       
                        <div class="content-decoration w975 h638 bor-std" style=" <?php if (is_file($images->image_intro)) {echo "background: url('".$images->image_intro."') no-repeat scroll right bottom #FFFFFF;";} else {echo "background: url('templates/3dmaler/img/main-img-bg.jpg') no-repeat scroll right bottom #FFFFFF;";} ;?>  ">
                        	<div class="content-inner">
                                <div class="content-view w520">
                                    <h2 class="blue-txt">Rediger oplysninger</h2>
                                    <form id="tilmeldMalerfirmaFormEdit" class="tilmeld-form" method="post" action="">
                                        <fieldset>
                                            <div class="input-set-ctn">
                                            	
                                            	<p class="input-set">
                                                	<label>Firmanavn<span>*</span></label>
                                                	<input class="input-txt" type="text" name="firma_navn" id="firma_navn" value="<?php if($rowuser->firma_navn) echo $rowuser->firma_navn; ?>" />
                                                </p>
                                                <p class="input-set">
                                                	<label>Nuværende adgangskode<span>*</span></label>
                                                	<input class="input-txt short" type="password" name="oldpassword" id="oldpassword" value="" />
                                                </p>
                                                
                                                 <p class="input-set">
                                                	<label>Ny adgangskode</label>
                                                	<input class="input-txt short" type="password" name="password" id="password" value="" />
                                                </p>
                                                <p class="input-set">
                                                	<label>Gentag ny adganskode</label>
                                                	<input class="input-txt short" type="password" name="password2" id="password2" value="" />
                                                </p> 
                                                <p class="input-set">
                                                	<label>Adresse<span>*</span></label>
                                                	<input class="input-txt" type="text" name="adresse" id="adresse" value="<?php if($rowuser->adresse) echo $rowuser->adresse; ?>" />
                                                <p class="input-set">
                                                	<label></label>
                                                	<input class="input-txt post-num" type="text" title="Postnr.*" name="post" id="post" value="<?php if($rowuser->post) echo $rowuser->post; ?>" />
                                                	<input class="Input-txt city" type="text" title="By*" name="by_" id="by_" value="<?php if($rowuser->by_) echo $rowuser->by_; ?>" />
                                                </p>
                                                
                                                <p class="input-set">
                                                	<label>CVR-nr.<span>*</span></label>
                                                	<input class="input-txt short marb15" type="text" name="cvr" id="cvr" value="<?php if($rowuser->cvr) echo $rowuser->cvr; ?>" />
                                                </p>
                                                <p class="input-set">
                                                	<label>Kontaktpersonens fornavn<span>*</span></label>
                                                	<input class="input-txt" type="text" name="name" id="name" value="<?php if($rowuser->name) echo $rowuser->name; ?>" />
                                                </p>
                                                <p class="input-set">
                                                	<label>Kontaktpersonens efternavn<span>*</span></label>
                                                	<input class="input-txt" type="text" name="lastname" id="lastname" value="<?php if($rowuser->lastname) echo $rowuser->lastname; ?>" />
                                                </p>
                                                <p class="input-set">
                                                	<label>Telefonnummer<span>*</span></label>
                                                	<input class="input-txt short" type="text" name="telefone" id="telefone" value="<?php if($rowuser->telefone) echo $rowuser->telefone; ?>" />
                                                </p>
                                                <p class="input-set">
                                                	<label>E-mail-adresse<span>*</span></label>
                                                	<input disabled="disabled" class="input-txt" type="text" name="email" id="email" value="<?php if($rowuser->email) echo $rowuser->email; ?>" />
                                                </p>
                                               
                                            </div>
                                            <div class="form-submit padt15">
                                                <input class="button reset-btn flr" type="reset" value="Nulstil" />
                                                 <input type="hidden" name="option" value="com_jobs" />
												 <input type="hidden" name="task" value="edituserinfo" />
												 <?php echo JHtml::_('form.token');?>
                                                 <input class="button send-btn  flr"  type="button" value="Godkend" onclick="$('#tilmeldMalerfirmaFormEdit').submit();" />
                                                
                                            </div>
                                           
                                           <input class="btnhidden thickbox flr" alt="#TB_inline?height=125&width=260&inlineId=tilmeldConfirm" type="hidden" value="Godkend" />
                                        <div id="tilmeldConfirm" style="display:none;">
                                            <div class="content-view">
                                            <span id="f_focus" style="display:none;"></span>
                                            <h2 class="blue-txt center"></h2>
                                            <p class="message" id="msgbox"></p>
                                            </div>
                                        </div> 
                                        </fieldset>
                                    </form>
                                </div>
                        	</div>
                        </div>
                        <!-- /Tilmeld Malerfirma Form-->
                        
                    </div>   

<?php
		/*
		$session->set('firma_navn','');
		$session->set('adresse', '');
		$session->set('post', '');
		$session->set('firma_navn', '');
		$session->set('by_','');
		$session->set('cvr', '');
		$session->set('telefone', '');
		$session->set('by_', '');
		$session->set('name', '');
		$session->set('lastname', '');
		$session->set('email', '');
		$session->set('password', '');
		*/
?>                    


<?php
return;
/**
 * @package		Joomla.Site
 * @subpackage	com_users
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 * @since		1.6
 */

defined('_JEXEC') or die;

JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
?>
<div class="registration<?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading')) : ?>
	<h1><?php echo $this->escape($this->params->get('page_heading')); ?></h1>
<?php endif; ?>

	<form id="member-registration" action="<?php echo JRoute::_('index.php?option=com_users&task=registration.register'); ?>" method="post" class="form-validate">
<?php foreach ($this->form->getFieldsets() as $fieldset): // Iterate through the form fieldsets and display each one.?>
	<?php $fields = $this->form->getFieldset($fieldset->name);?>
	<?php if (count($fields)):?>
		<fieldset>
		<?php if (isset($fieldset->label)):// If the fieldset has a label set, display it as the legend.?>
			<legend><?php echo JText::_($fieldset->label);?></legend>
		<?php endif;?>
			<dl>
		<?php foreach($fields as $field):// Iterate through the fields in the set and display them.?>
			<?php if ($field->hidden):// If the field is hidden, just display the input.?>
				<?php echo $field->input;?>
			<?php else:?>
				<dt>
				<?php echo $field->label; ?>
				<?php if (!$field->required && $field->type != 'Spacer'): ?>
					<span class="optional"><?php echo JText::_('COM_USERS_OPTIONAL');?></span>
				<?php endif; ?>
				</dt>
				<dd><?php echo $field->input;?></dd>
			<?php endif;?>
		<?php endforeach;?>
			</dl>
		</fieldset>
	<?php endif;?>
<?php endforeach;?>
		<div>
			<button type="submit" class="validate"><?php echo JText::_('JREGISTER');?></button>
			<?php echo JText::_('COM_USERS_OR');?>
			<a href="<?php echo JRoute::_('');?>" title="<?php echo JText::_('JCANCEL');?>"><?php echo JText::_('JCANCEL');?></a>
			<input type="hidden" name="option" value="com_users" />
			<input type="hidden" name="task" value="registration.register" />
			<?php echo JHtml::_('form.token');?>
		</div>
	</form>
</div>
